#pragma once
#include "log.hpp"
#include <iostream>
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
#include "Nocopy.hpp"
#include <cerrno>
#include "Comm.hpp"
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <strings.h>
#include <string.h>

class InetAddr
{
private:
    std::string _ip;
    uint16_t _port;
    struct sockaddr_in _addr;    //将套接字信息都在此类初始化
public:
    InetAddr(struct sockaddr_in &addr):_addr(addr)  
    {
        _port = ntohs(addr.sin_port);
        _ip = inet_ntoa(addr.sin_addr);
    }

    std::string getip()
    {
        return _ip;
    }

    uint16_t getport()
    {
        return _port;
    }

    struct sockaddr_in getaddr()
    {
        return _addr;
    }

    std::string PrintDebug()
    {
        std::string Info = _ip+":"+std::to_string(_port);
        return Info;
    }

    ~InetAddr() {}
};